<%@page contentType="text/html" pageEncoding="UTF-8" import="Funcionalidad.*,java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<jsp:include page="../Apariencia/Cabecera.jsp"/>
<%

        if (session.getAttribute("loginuser") != null) {
            int rol = (Integer) session.getAttribute("loginrol");
            if (rol == 1) {
%>

<html>
    <script laguage="javascript">
        function activar(elemento){

            if(elemento.listagaleria.options[elemento.listagaleria.selectedIndex].text=="--Crear Nueva--"){
                var textfield = document.createElement('input');
                textfield.setAttribute('type','text');
                textfield.setAttribute('id', 'nueva');
                document.getElementById("aparece").style.display = "inline";
            }
            else{
                document.getElementById("aparece").style.display = "none";}
        }
    </script>
    <head>
        <title>FLOG - Administraci&oacute;n</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <div id="administracion" class="admonNuevaFoto">
        <body>
            <h1>Administraci&oacute;n Subir Nueva Foto</h1>
            <form method="post" enctype="multipart/form-data" action="SubirFoto.jsp" name="formulario">
                <table>
                    <tr>
                        <td><h4>Titulo:</h4></td>
                        <td><input name="titulo" type="text"/></td>
                    </tr>
                    <tr>
                        <td><h4>Foto:</h4></td>
                        <td><input type="file" name="foto" /></td>
                    </tr>
                    <tr>
                        <td>
                            <% List<Galeria> galerias = new ArrayList();
                        try {
                            galerias = Galerias.consultaGalerias();
                        } catch (Exception ex) {
                            out.print(ex.getMessage());
                        }%>
                            <select name="listagaleria" onChange="activar(this.form)">
                                <option value=" " selected="selected">[Seleccione su opcion]
                                <%Iterator it = galerias.iterator();
                        while (it.hasNext()) {
                            Galeria galeria = (Galeria) it.next();%>
                                <option value="<%= galeria.getId()%>"><%= galeria.getNombre()%></option>
                                <%}%>
                                <option value="nueva">--Crear Nueva--</option>
                            </select>
                            <td colspan="2" id="aparece" style="display:none"><input type="text" name="otras" /></td>
                        </td>
                    </tr>
                    <tr>
                        <td><input type="submit" name="envio" value="Enviar foto" /></td>
                    </tr>
                </table>


            </form>

        </body>
    </div>
</html>
<%
                }
else  {
                response.sendRedirect("../Apariencia/VistaPost.jsp");
            }
        }
%>